Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.autocorrelate = t, exports.findPitch = function(e, r) {
    const n = function(e) {
        const r = t(e);
        let n = 2 * r[0];
        if (0 === n) {
            const e = new Array(r.length);
            return e.fill(0), e;
        }
        return r.map((t, r) => {
            const o = n, l = e.length - r - 1;
            return n -= e[r] * e[r] + e[l] * e[l], 2 * t / o;
        });
    }(e), o = function(e) {
        const t = [];
        let r, n = !1, o = -1;
        for (let l = 1; l < e.length; l++) e[l - 1] < 0 && e[l] > 0 ? (n = !0, o = l, r = e[l]) : e[l - 1] > 0 && e[l] < 0 ? (n = !1, 
        -1 !== o && t.push(o)) : n && e[l] > r && (r = e[l], o = l);
        return t;
    }(n);
    if (0 === o.length) return [ 0, 0 ];
    const l = Math.max(...o.map(e => n[e])), c = .9 * l, s = o.find(e => n[e] >= c);
    return void 0 === s ? [ 0, 0 ] : [ r / s, n[s] ];
};

var e = require("4C2836D32DC8E0DF2A4E5ED4BD57FFC0.js");

function t(t) {
    const r = new e.FFT((0 === (n = 2 * t.length) && (n += 1), --n, n |= n >>> 1, n |= n >>> 2, 
    n |= n >>> 4, n |= n >>> 8, 1 + (n |= n >>> 16)));
    var n;
    const o = new Array(r.size);
    t.forEach((e, t) => {
        o[t] = e;
    }), o.fill(0, t.length);
    const l = r.createComplexArray();
    r.realTransform(l, o), r.completeSpectrum(l);
    for (let e = 0; e < l.length; e += 2) l[e] = l[e] * l[e] + l[e + 1] * l[e + 1], 
    l[e + 1] = 0;
    const c = r.createComplexArray();
    r.inverseTransform(c, l);
    const s = new Array(t.length);
    for (let e = 0; e < t.length; e++) s[e] = c[2 * e];
    return s;
}